package demo_JUC.LockObj;

import java.util.concurrent.TimeUnit;

public class demo005 {
    public static void main(String[] args) {
        // 以下程序，会先sendSms，后call
        // 方法上有static，实际上synchronized锁的对象是Phone的class

        new Thread(()->{
            Phone.sendSms();}, "A").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{
            Phone.call();}, "B").start();
    }

    static class Phone{
        public static synchronized void sendSms(){
            try {
                TimeUnit.SECONDS.sleep(4);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("sendSms");
        }
        public static synchronized void call(){
            System.out.println("call");
        }
        public void hello(){
            System.out.println("hello");
        }
    }
}
